package com.rop.system.custom;

import com.rop.util.MD5;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Objects;

/**
 * @Title: CustomizeMd5Password
 * @Author Rop
 * @Date 2023/5/12 11:40
 * @description: 自定义密码组件
 */

@Configuration
public class CustomizeMd5Password implements PasswordEncoder {

    /**
     * 加密
     */
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }

    /**
     * 密码匹配
     */
    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return Objects.equals(s, MD5.encrypt(charSequence.toString()));
    }
}
